#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int main() {
	
	int n,m;
	cin>>n>>m;
	vector<vector<int>> vecArr(n,vector<int>(m));
	vector<ll> row(n),col(m);
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			scanf("%d",&vecArr[i][j]);
			row[i]+=vecArr[i][j];
			col[j]+=vecArr[i][j];
		}
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			printf("%lld ",row[i]+col[j]-vecArr[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}
